import { useEffect, useState, useReducer } from "react";


export default function Effect() {
    const [res, dispatch] = useReducer(Reducer, { result: 20, suggest: '长袖' });

    function Reducer(state, action) {
        switch (action.type) {
            case 'add':
                return { result: state.result + 1, suggest: state.result > 25 ? '短袖' : '长袖' }
            case 'minus':
                return { result: state.result - 1, suggest: state.result < 25 ? '长袖' : '短袖' }
            default:
                return state
        }
    }
    return (
        <div>
            <button onClick={() => dispatch({ type: 'add' })}>+</button>
            <button onClick={() => dispatch({ type: 'minus' })}>-</button>
            <div>{res.result}</div>
        </div>
    )
}
